<template>
<div style="padding: 20px">
  <vxe-table
      border
      show-overflow
      :data="dataList"
      :column-config="{resizable: true}"
      :edit-config="{trigger: 'dblclick', mode: 'cell'}"
      @edit-closed="updateData">
    <vxe-column type="seq" width="60"></vxe-column>
    <vxe-column field="name" title="区/县">
      <template #edit="{ row }">
        <vxe-input v-model="row.name" type="text"></vxe-input>
      </template>
    </vxe-column>
    <vxe-column field="is_create" title="新增" :edit-render="{}">
      <template #default="{ row }">
        <span v-if="row.is_create === '0'">关</span>
        <span v-if="row.is_create === '1'">开</span>
      </template>
      <template #edit="{ row }">
        <vxe-select v-model="row.is_create" type="text" :options="switchList" transfer></vxe-select>
      </template>
    </vxe-column>
    <vxe-column field="is_update" title="修改" :edit-render="{}">
      <template #default="{ row }">
        <span v-if="row.is_update === '0'">关</span>
        <span v-if="row.is_update === '1'">开</span>
      </template>
      <template #edit="{ row }">
        <vxe-select v-model="row.is_update" type="text" :options="switchList" transfer></vxe-select>
      </template>
    </vxe-column>
    <vxe-column field="is_delete" title="删除" :edit-render="{}">
      <template #default="{ row }">
        <span v-if="row.is_delete === '0'">关</span>
        <span v-if="row.is_delete === '1'">开</span>
      </template>
      <template #edit="{ row }">
        <vxe-select v-model="row.is_delete" type="text" :options="switchList" transfer></vxe-select>
      </template>
    </vxe-column>
    <vxe-column field="is_qy" title="迁移" :edit-render="{}">
      <template #default="{ row }">
        <span v-if="row.is_qy === '0'">关</span>
        <span v-if="row.is_qy === '1'">开</span>
      </template>
      <template #edit="{ row }">
        <vxe-select v-model="row.is_qy" type="text" :options="switchList" transfer></vxe-select>
      </template>
    </vxe-column>
  </vxe-table>
</div>
</template>

<script>
import { findGridSwitchList, updateGridSwitch } from '../../api/eventlist'
export default {

  name: 'index',
  data () {
    return {
      dataList: [],
      switchList: [
        { label: '关', value: '0' },
        { label: '开', value: '1' }
      ]
    }
  },
  methods: {
    init () {
      findGridSwitchList().then(ret => {
        if (ret.data.errcode === 0) {
          this.dataList = ret.data.data
        } else {
          this.$Notice.error({ title: '查询失败！', desc: ret.data.errmsg })
        }
      })
    },
    updateData ({ row, column }) {
      updateGridSwitch(row).then(ret => {
        if (ret.data.errcode === 0) {
          this.$Notice.success({ title: '修改成功！', desc: ret.data.errmsg })
          this.init()
        } else {
          this.$Notice.error({ title: '修改失败！', desc: ret.data.errmsg })
          this.init()
        }
      })
    }
  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped>

</style>
